var app = angular.module('app',[]);
app.service('crsj',function(){
	this.cr=function(dataObj){
		if(dataObj){
			dataStr = JSON.stringify(dataObj);
			localStorage.setItem('ly',dataStr);
		}else{
			localStorage.setItem('ly','{"info":[]}');
		}
	}
	this.qu=function(){
		dataStr = localStorage.getItem('ly');
		if(dataStr){
			dataObj = JSON.parse(dataStr);
			return dataObj
		}
	}
})
app.controller('ct1',['$scope','crsj',function($scope,crsj){
	if(crsj.qu()){
		$scope.zhi=crsj.qu().info
	}else{
		crsj.cr()
	}
	$scope.add=function(){
		dataObj =crsj.qu();
		dataObj.info.push({"name":$scope.name,"money":$scope.money,"time":$scope.time});
		$scope.zhi = dataObj.info;
		crsj.cr(dataObj);
	}
	$scope.remove=function(index){
		dataObj =crsj.qu();
		dataObj.info.splice(index,1);
		$scope.zhi = dataObj.info;
		crsj.cr(dataObj);
	}
}])